<?php

namespace app\index\controller;

use think\Controller;
use think\Db;
use think\Request;

class Register extends Controller
{
    //加载注册模板
    public function register()
    {
        return view();
    }

    //处理注册
    public function doRegister()
    {
        $pass = md5(input('upass'));
        $data = [
            'utel'=>input('utel'),
            'username'=>input('username'),
            'upass'=>$pass
        ];
        $res = Db::name('vip')
        ->insert($data);
        if($res>0){
            $this->success('注册成功',url('admin/Main/index'));
        }

    }

    //验证手机号的唯一性
    public function checktel(Request $request)
    {
        $tel = json_decode($request->post('tel'));
        $res = Db::name('vip')
            ->where('utel',$tel)
            ->find();
        if(empty($res)){
            return true;
        }else{
            return false;
        }
    }

//    验证用户名唯一性
    public function checkusername(Request $request)
    {
        $username = $request->post('username');
        $res = Db::name('vip')
            ->where('username',$username)
            ->find();
        if(empty($res)){
            return true;
        }else{
            return false;
        }
    }
}
